/*************************************************************************
	> File Name: myled.c
	> Author: life
	> Created Time: 2021年10月26日 星期二 13时56分23秒
 ************************************************************************/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/delay.h>


static struct pinctrl *mazled_pin_ctrl = NULL;

static int gpio_reset_probe(struct platform_device *pdev)
{
	struct pinctrl_state  *mazled = NULL;
	int ret = 0;
	
	mazled_pin_ctrl = devm_pinctrl_get(&pdev->dev);//获得pinctrl节点信息
	if(IS_ERR(mazled_pin_ctrl))
	{
		printk("devm_pinctrl_get is error\n");
		ret = PTR_ERR(mazled_pin_ctrl);
		return ret;
	}
		//devm_gpiod_get(&pdev->dev, NULL, 0);
	mazled = pinctrl_lookup_state(mazled_pin_ctrl, "high");//得到相应的pin的状态，后面的参数和pinctrl-names中的字符串对应
	if(IS_ERR(mazled))
	{
		printk("get the state of the mz391-rst-on is fail\n");
		ret = PTR_ERR(mazled);
		return ret;
	}

	pinctrl_select_state(mazled_pin_ctrl, mazled);//执行pinctrl节点的pinctrl-0中的具体操作

	return ret;
}

static const struct of_device_id  gpio_reset_of_id[] = {
	{.compatible = "maz, led",},//和dts文件中的节点细想匹配
	{}
};

static int gpio_reset_remove(struct platform_device *pdev)
{
	return 0;	
}

static struct platform_driver mazled_platform_driver = {
	.probe = gpio_reset_probe,
	.remove = gpio_reset_remove,
	.driver = {
		.name = "mazled",
		.owner = THIS_MODULE,
		.of_match_table = gpio_reset_of_id,
	},
};

static int __init leds_init(void)
{
	printk("leds_init pinctrl\n");
	platform_driver_register(&mazled_platform_driver);
	return 0;
}

static void __exit leds_exit(void)
{
	
	platform_driver_unregister(&mazled_platform_driver);
	printk(KERN_INFO"leds_exit exit\n");
}
module_init(leds_init);
module_exit(leds_exit);

/* 描述驱动程序的一些信息，不是必须的 */
MODULE_AUTHOR("ChenBlue");
MODULE_VERSION("0.1.0");
MODULE_DESCRIPTION("raspberry LED Driver");
MODULE_LICENSE("GPL");


